package org.triumphxx.rule;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.triumphxx.rule.dto.NameRuleDTO;
import org.triumphxx.ruletemplate.AbstractRule;

import static org.triumphxx.constant.RuleConstant.MATCH_NAME;

/**
 * @author:triumphxx
 * @Date: 2024/1/8
 * @Time: 14:27
 * @微信公众号：思考集结处
 * @网站：http://blog.triumphxx.com.cn
 * @GitHub https://github.com/triumphxx
 * @Desc: 姓名规则
 **/
@Data
@Slf4j
public class NameRule extends AbstractRule {
    @Override
    public boolean execute(Object ruleDTO) {
        NameRuleDTO nameRuleDTO = new NameRuleDTO();
        //对象属性赋值
        BeanUtils.copyProperties(ruleDTO, nameRuleDTO);
        log.info("开始执行关于姓名的校验规则，传入的姓名信息为:{}", nameRuleDTO.getName());
        if (nameRuleDTO.getName().startsWith(MATCH_NAME)) {
            return true;
        }
        return false;
    }

}
